﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Security.Cryptography;
using System.IO;
//using VHKMLib.VHEntities;
//using KMLib = VHKMLib.VHEntities;
using System.Xml;
//using ICSharpCode.SharpZipLib.Core;
//using ICSharpCode.SharpZipLib.Zip;
using System.Text.RegularExpressions;
using System.Net;
using System.Collections;
//using cn.net.drm.edi;
namespace VHKMLib.Common
{
    public class Base
    {

        private const string KEY = "VZCDFKBG";
        /// <summary>
        /// DES加密
        /// </summary>
        /// <param name="pToEncrypt"></param>
        /// <returns></returns>
        public static string MD5Encrypt(string pToEncrypt)
        {
            try
            {
                DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
                des.Key = ASCIIEncoding.ASCII.GetBytes(KEY);
                des.IV = ASCIIEncoding.ASCII.GetBytes(KEY);
                MemoryStream ms = new MemoryStream();
                CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
                cs.Write(inputByteArray, 0, inputByteArray.Length);
                cs.FlushFinalBlock();
                StringBuilder ret = new StringBuilder();
                foreach (byte b in ms.ToArray())
                    ret.AppendFormat("{0:X2}", b);
                ret.ToString();
                return ret.ToString();
            }
            catch (Exception)
            {
                return "";
            }
        }



        /// <summary>
        /// DES解密
        /// </summary>
        /// <param name="sToDecrypt"></param>
        /// <returns></returns>
        public static string MD5Decrypt(string sToDecrypt)
        {
            try
            {
                DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                byte[] inputByteArray = new byte[sToDecrypt.Length / 2];
                for (int x = 0; x < sToDecrypt.Length / 2; x++)
                {
                    int i = (Convert.ToInt32(sToDecrypt.Substring(x * 2, 2), 16));
                    inputByteArray[x] = (byte)i;
                }
                des.Key = ASCIIEncoding.ASCII.GetBytes(KEY);
                des.IV = ASCIIEncoding.ASCII.GetBytes(KEY);
                MemoryStream ms = new MemoryStream();
                CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
                cs.Write(inputByteArray, 0, inputByteArray.Length);
                cs.FlushFinalBlock();
                StringBuilder ret = new StringBuilder();
                return System.Text.Encoding.Default.GetString(ms.ToArray());
            }
            catch (Exception ex)
            {
                return "";
            }
        }



        /// <summary>
        /// 压缩文件
        /// </summary>
        /// <param name="files">要压缩的文件列表</param>
        /// <param name="zipFile">压缩包放置的位置</param>
        /// <returns></returns>
        //public static bool ZipFiles(string[] files, string zipFile)
        //{
        //    bool bSuccess = false;
        //    if (files == null || files.Length == 0)
        //    {
        //        bSuccess = false;
        //    }
        //    ZipOutputStream zipOs = new ZipOutputStream(File.Create(zipFile));
        //    try
        //    {
        //        byte[] buffer = new byte[4096];
        //        foreach (string file in files)
        //        {
        //            if (!File.Exists(file)) continue;
        //            FileStream fs = File.OpenRead(file);
        //            try
        //            {
        //                string name = Path.GetFileName(file);
        //                ZipEntry entry = new ZipEntry(name);
        //                entry.DateTime = DateTime.Now;
        //                entry.Size = fs.Length;
        //                zipOs.PutNextEntry(entry);
        //                StreamUtils.Copy(fs, zipOs, buffer);
        //            }
        //            finally
        //            {
        //                fs.Close();
        //            }
        //        }
        //        zipOs.Finish();
        //        bSuccess = true;
        //    }
        //    finally
        //    {
        //        zipOs.Close();
        //    }
        //    return bSuccess;
        //}

        //public static bool ZipFiles(string dPath, object[] sFileList, object[] sPathList)
        //{
        //    bool bSuccess = false;
        //    //创建压缩文件
        //    ICSharpCode.SharpZipLib.Zip.ZipConstants.DefaultCodePage = 936;
        //    ICSharpCode.SharpZipLib.Checksums.Crc32 m_Crc = new ICSharpCode.SharpZipLib.Checksums.Crc32();
        //    ICSharpCode.SharpZipLib.Zip.ZipOutputStream m_ZipStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(System.IO.File.Create(dPath));
        //    m_ZipStream.SetLevel(6);
        //    string fileNameToZip, filePathToZip;
        //    try
        //    {
        //        for (int i = 0; i < sFileList.Length; i++)
        //        {
        //            //物理路径
        //            fileNameToZip = (string)sFileList[i];

        //            //Zip文件路径
        //            filePathToZip = (string)sPathList[i];
        //            string aLastName = fileNameToZip.Substring(fileNameToZip.LastIndexOf(".")).ToLower();
        //            if (!filePathToZip.ToLower().EndsWith(aLastName))
        //            {
        //                filePathToZip = filePathToZip + aLastName;
        //            }
        //            FileStream fso = File.OpenRead(fileNameToZip);

        //            //读到文件到内存
        //            byte[] buffer = new byte[fso.Length];
        //            fso.Read(buffer, 0, buffer.Length);

        //            // 创建一个Zip实体
        //            ICSharpCode.SharpZipLib.Zip.ZipEntry zipEntry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(filePathToZip);
        //            zipEntry.DateTime = DateTime.Now;
        //            zipEntry.Size = fso.Length;
        //            fso.Close();
        //            fso = null;

        //            // 格式化内容
        //            m_Crc.Reset();
        //            m_Crc.Update(buffer);
        //            zipEntry.Crc = m_Crc.Value;

        //            // 加入流程
        //            m_ZipStream.PutNextEntry(zipEntry);
        //            m_ZipStream.Write(buffer, 0, buffer.Length);
        //        }
        //        m_ZipStream.Finish();
        //        m_ZipStream.Close();
        //        m_ZipStream = null;
        //        bSuccess = true;
        //    }
        //    finally
        //    {

        //    }
        //    return bSuccess;
        //}

        /// <summary>
        /// 判断文件是否存在
        /// </summary>
        /// <param name="sFile"></param>
        /// <returns></returns>
        public static bool FileExists(string sFile)
        {
            return File.Exists(sFile);
        }

        /// <summary>
        /// 判断目录是否存在
        /// </summary>
        /// <param name="sDirectory"></param>
        /// <returns></returns>
        public static bool DirectoryExists(string sDirectory)
        {
            return Directory.Exists(sDirectory);
        }

    }

    public static class HashtableExtend
    {
        public static string DefaultValue(this Hashtable src, object key, string def)
        {
            if (src[key] == null)
                return def;
            else
                return src[key].ToString();
        }
    }

    public static class StringExtend
    {

        private const string KEY = "SPOEFATK";

        #region Enum

        #endregion

        /// <summary>
        /// 比较字符串是不是和当前字符串相同
        /// </summary>
        /// <param name="sSender"></param>
        /// <param name="sCompareTo">要与当前字符串比较的字符串</param>
        /// <param name="bCase">是否区分大小写</param>
        /// <returns></returns>
        public static bool IsSame(this string sSender, string sCompareTo, bool bCase)
        {
            if ((sSender == null && sCompareTo != null) || (sSender != null && sCompareTo == null))
            {
                return false;
            }
            if (bCase)
            {
                //判断大小写

                return sSender.Trim() == sCompareTo.Trim();
            }
            else
            {
                return sSender.Trim().ToLower() == sCompareTo.ToLower().Trim();
            }
        }

        /// <summary>
        /// 取字符串的指定长度

        /// </summary>
        /// <param name="src"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public static string CutString(this string src, int len)
        {
            if (string.IsNullOrEmpty(src))
            {
                return string.Empty;
            }
            else
            {
                string des = "";
                int n = 0;
                foreach (char ch in src)
                {
                    n += System.Text.Encoding.Default.GetByteCount(ch.ToString());
                    if (n > len)
                        break;
                    else
                        des += ch;
                }
                des += (src.Length > len) ? "..." : "";
                return des;
            }
        }

        public static string ReplaceRow(this string src)
        {
            if (string.IsNullOrEmpty(src))
            {
                return string.Empty;
            }
            else
            {
                return src.Replace("\r", "").Replace("\n", "");
            }
        }

        public static bool In(this string src, string str)
        {
            if (string.IsNullOrEmpty(src))
            {
                return false;
            }
            else
            {
                return src.IndexOf(str) > -1;
            }
        }



        public static string AppendTag(this string src, string tag)
        {
            if (string.IsNullOrEmpty(src))
            {
                return string.Empty;
            }
            else
            {
                return string.Format("{0}{1}", tag, src);
            }
        }
        /// <summary>
        /// 判断一个字符串是否为Null或字符串空

        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        public static bool IsNullOrEmpty(this string src)
        {
            return string.IsNullOrEmpty(src);
        }

        /// <summary>
        /// 判断是否是指定类型图片

        /// </summary>
        /// <param name="src"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool IsImageType(this string src, string type)
        {
            string sExt = Path.GetExtension(src);
            return sExt.IsSame(type, false);
        }

        /// <summary>
        /// SQL 查询过滤
        /// </summary>
        /// <param name="srcStr"></param>
        /// <returns></returns>
        public static string SqlFilter(this string src)
        {
            if (string.IsNullOrEmpty(src))
                return string.Empty;
            else
            {
                string reStr = src.Replace("'", "''");
                return reStr;
            }
        }

        public static Hashtable FilePathPool = new Hashtable();
        /// <summary>
        /// 加密
        /// </summary>
        public static string MD5EncryptFilePath(this string pToEncrypt)
        {
            try
            {

                string guId = Guid.NewGuid().ToString();
                if (!string.IsNullOrEmpty(pToEncrypt))
                {
                    FilePathPool.Add(guId, pToEncrypt);
                }
                return guId;
            }
            catch (Exception)
            {
                return "";
            }
        }
        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="sToDecrypt"></param>
        /// <returns></returns>
        public static string MD5DecryptFilePath(this string sToDecrypt)
        {
            try
            {
                string path = string.Empty;
                if (FilePathPool[sToDecrypt] != null)
                    path = (string)FilePathPool[sToDecrypt];
                return path;
            }
            catch (Exception ex)
            {
                return "";
            }
        }
        /// <summary>
        /// DES加密
        /// </summary>
        /// <param name="pToEncrypt"></param>
        /// <returns></returns>
        public static string MD5Encrypt(this string pToEncrypt)
        {
            try
            {
                DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
                des.Key = ASCIIEncoding.ASCII.GetBytes(KEY);
                des.IV = ASCIIEncoding.ASCII.GetBytes(KEY);
                MemoryStream ms = new MemoryStream();
                CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
                cs.Write(inputByteArray, 0, inputByteArray.Length);
                cs.FlushFinalBlock();
                StringBuilder ret = new StringBuilder();
                foreach (byte b in ms.ToArray())
                    ret.AppendFormat("{0:X2}", b);
                ret.ToString();
                return ret.ToString();
            }
            catch (Exception)
            {
                return "";
            }
        }

        /// <summary>
        /// MD5解密
        /// </summary>
        /// <param name="sToDecrypt"></param>
        /// <returns></returns>
        public static string MD5Decrypt(this string sToDecrypt)
        {
            try
            {
                DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                byte[] inputByteArray = new byte[sToDecrypt.Length / 2];
                for (int x = 0; x < sToDecrypt.Length / 2; x++)
                {
                    int i = (Convert.ToInt32(sToDecrypt.Substring(x * 2, 2), 16));
                    inputByteArray[x] = (byte)i;
                }
                des.Key = ASCIIEncoding.ASCII.GetBytes(KEY);
                des.IV = ASCIIEncoding.ASCII.GetBytes(KEY);
                MemoryStream ms = new MemoryStream();
                CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
                cs.Write(inputByteArray, 0, inputByteArray.Length);
                cs.FlushFinalBlock();
                StringBuilder ret = new StringBuilder();
                return System.Text.Encoding.Default.GetString(ms.ToArray());
            }
            catch (Exception ex)
            {
                return "";
            }
        }

        public static bool CanOnlineView(this string filePath)
        {
            bool canView = false;
            if (!string.IsNullOrEmpty(filePath))
            {
                string ext = Path.GetExtension(filePath);
                if (ext.ToLower() == ".tif"
                    || ext.ToLower() == ".tiff"
                    || ext.ToLower() == ".pdf"
                    || ext.ToLower() == ".bmp"
                    || ext.ToLower() == ".gif"
                    || ext.ToLower() == ".jpg"
                    || ext.ToLower() == ".jpeg"
                    || ext.ToLower() == ".png"
                    || ext.ToLower() == ".dwf"
                    || ext.ToLower() == ".swf"
                    || ext.ToLower() == ".flv"
                    || ext.ToLower() == ".wrl")
                    canView = true;
            }
            return canView;
        }

        public static ArrayList SplitByTag(this string src, string tag)
        {
            ArrayList rList = new ArrayList();
            if (src.IndexOf(tag) > -1)
            {
                string[] list = src.Split(new string[] { tag }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in list)
                    rList.Add(s.Trim());
            }
            else
            {
                rList.Add(src.Trim());
            }
            return rList;
        }

        public static int GetNumber(this string src)
        {
            int idx = src.IndexOf(" ");
            if (idx > 0)
                src = src.Substring(0, idx);
            string s = System.Text.RegularExpressions.Regex.Replace(src, @"[^\d]*", "");
            try
            {
                return Int32.Parse(s);
            }
            catch (Exception)
            {
                return -1;
            }
        }

        public static string GetSpec(this string src)
        {
            if (!string.IsNullOrEmpty(src))
            {
                int idx = src.IndexOf(" ");
                if (idx > 0)
                {
                    string spec = src.Substring(0, idx);
                    string pattern = @"\d+\w*";
                    string s = Regex.Replace(spec, pattern, "");
                    if (!string.IsNullOrEmpty(s))
                        return s;
                    else
                        return spec;
                }
                else
                {
                    return src.Substring(0, 1);
                }
            }
            else
            {
                return string.Empty;
            }
        }

    }

    public static class DateTimeExtend
    {
        /// <summary>
        /// 返回日期
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string ToDateString(this DateTime dt)
        {
            return dt.ToString("yyyy-MM-dd");
        }
        /// <summary>
        /// 返回24小时制 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string ToDate24String(this DateTime dt)
        {
            return dt.ToString("yyyy-MM-dd HH:mm:ss");
        }
        /// <summary>
        /// 返回12小时制

        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string ToDate12String(this DateTime dt)
        {
            return dt.ToString("yyyy-MM-dd HH:mm:ss");
        }
        /// <summary>
        /// 返回本周开始日期，星期一
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DateTime GetWeekStartDate(this DateTime dt)
        {
            return dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d")));
        }
        /// <summary>
        /// 返回本周结束日期，星期日
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DateTime GetWeekEndDate(this DateTime dt)
        {
            return dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d"))).AddDays(6);
        }
        /// <summary>
        /// 返回本月开始日期

        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DateTime GetMonthStartDate(this DateTime dt)
        {
            return dt.AddDays(1 - dt.Day);
        }
        /// <summary>
        /// 返回本月结束日期
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DateTime GetMonthEndDate(this DateTime dt)
        {
            return dt.AddDays(1 - dt.Day).AddMonths(1).AddDays(-1);
        }
        /// <summary>
        /// 返回本季度开始日期

        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DateTime GetQuarterStartDate(this DateTime dt)
        {
            return dt.AddMonths(0 - (dt.Month - 1) % 3).AddDays(1 - dt.Day);
        }
        /// <summary>
        /// 返回本季度结束日期

        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DateTime GetQuarterEndDate(this DateTime dt)
        {
            return dt.AddMonths(0 - (dt.Month - 1) % 3).AddDays(1 - dt.Day).AddMonths(3).AddDays(-1);
        }
        /// <summary>
        /// 返回本年开始日期

        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DateTime GetYearStartDate(this DateTime dt)
        {
            return new DateTime(dt.Year, 1, 1);
        }
        /// <summary>
        /// 返回本年结束日期
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DateTime GetYearEndDate(this DateTime dt)
        {
            return new DateTime(dt.Year, 12, 31);
        }

    }

    public static class ObjectExtend
    {
        /// <summary>
        /// 取对象属性的值，当对象为Null值时返回空。

        /// </summary>
        /// <param name="obj"></param>
        /// <param name="attr"></param>
        /// <returns></returns>
        public static string GetSafePropertyStringValue(this Object obj, string attr)
        {
            string res = string.Empty;
            if (obj != null)
            {
                PropertyInfo[] attrs = obj.GetType().GetProperties();
                PropertyInfo ext = attrs.Where(o => o.Name == attr.Trim()).FirstOrDefault();
                if (ext == null)
                    res = string.Empty;
                else
                {
                    object o = ext.GetValue(obj, null);
                    res = o == null ? string.Empty : o.ToString();
                }
            }
            return res;
        }

        public static List<T> MakeList<T>(this T t, params T[] items)
        {
            return new List<T>(items);
        }

        //记录日志到文件
        public static void Log2File(this string strLog, params object[] parms)
        {
            try
            {
                string logPath = @"c:\temp";
                if (!Directory.Exists(logPath))
                    Directory.CreateDirectory(logPath);
                string LogFile = logPath + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".log";
                if (!File.Exists(LogFile))
                {
                    StreamWriter rw = File.CreateText(LogFile);
                    rw.Close();
                }
                if (parms != null && parms.Length > 0)
                    strLog += parms[0].ToString();
                StreamWriter sw = new StreamWriter(LogFile, true, System.Text.Encoding.Default);
                sw.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "	" + strLog + "\r\n");
                sw.Flush();
                sw.Close();
            }
            catch (Exception) { }
        }
    }
    public static class IntExtend
    {
        public static string RandomNumber(this int src, int len)
        {
            byte[] bytes = new byte[len];
            System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
            rng.GetBytes(bytes);
            return src.ToString() + BitConverter.ToInt32(bytes, 0).ToString();
        }
        public static string FormatQty(this int src)
        {
            string tmp = string.Empty;
            if (src == 0)
                tmp = "0";
            else
            {
                string qty = src.ToString();
                string Fmt2 = "#,###.00";
                string Fmt0 = "#,###";
                double d = 0D;
                if (qty.IndexOf('.') > -1)
                {
                    if (double.TryParse(qty, out d))
                        tmp = d.ToString(Fmt2);
                }
                else
                {
                    if (double.TryParse(qty, out d))
                        tmp = d.ToString(Fmt0);
                }
            }
            return tmp;
        }
        public static string FormatFileSize(this int src)
        {
            string tmp = string.Empty;

            string fileSizeFormat = "fs";
            Decimal OneKiloByte = 1024M;
            Decimal OneMegaByte = OneKiloByte * 1024M;
            Decimal OneGigaByte = OneMegaByte * 1024M;
            Decimal size = Convert.ToDecimal(src);
            string suffix;
            if (size > OneGigaByte)
            {
                size /= OneGigaByte;
                suffix = "GB";
            }
            else if (size > OneMegaByte)
            {
                size /= OneMegaByte;
                suffix = "MB";
            }
            else if (size > OneKiloByte)
            {
                size /= OneKiloByte;
                suffix = "kB";
            }
            else
            {
                suffix = " B";
            }
            string precision = fileSizeFormat.Substring(2);
            if (String.IsNullOrEmpty(precision)) precision = "2";
            return String.Format("{0:N" + precision + "}{1}", size, suffix);
        }
        public static string ToArchiveTable(this int src)
        {
            return string.Format("TB_Archive_{0}", (src < 0) ? 0 : src);
        }
    }
    public static class LongExtend
    {
        public static string FormatFileSize(this long src)
        {
            string tmp = string.Empty;

            string fileSizeFormat = "fs";
            Decimal OneKiloByte = 1024M;
            Decimal OneMegaByte = OneKiloByte * 1024M;
            Decimal OneGigaByte = OneMegaByte * 1024M;
            Decimal size = Convert.ToDecimal(src);
            string suffix;
            if (size > OneGigaByte)
            {
                size /= OneGigaByte;
                suffix = "GB";
            }
            else if (size > OneMegaByte)
            {
                size /= OneMegaByte;
                suffix = "MB";
            }
            else if (size > OneKiloByte)
            {
                size /= OneKiloByte;
                suffix = "kB";
            }
            else
            {
                suffix = " B";
            }
            string precision = fileSizeFormat.Substring(2);
            if (String.IsNullOrEmpty(precision)) precision = "2";
            return String.Format("{0:N" + precision + "}{1}", size, suffix);
        }
    }

    public static class VHArchiveExtend
    {

        /// <summary>
        /// 将VHArchive转换为一个知识库项目
        /// </summary>
        /// <param name="arc"></param>
        /// <returns></returns>
        //public static VHProject ToProject(this KMLib.VHArchive arc)
        //{
        //    return new VHProject(arc);
        //}

        /// <summary>
        /// 在当前档案下边找指定名称的档案，支持模糊查找
        /// </summary>
        /// <param name="arc"></param>
        /// <param name="sArchiveName"></param>
        /// <returns></returns>
        //public static KMLib.VHArchive GetSubArchiveDetail(this KMLib.VHArchive arc, int iClassID, int iType, string sArchiveName)
        //{
        //    if (arc == null) return null;
        //    List<KMLib.VHArchive> arcs = VHHandler.GetSubArchives(iClassID, arc.ArchiveID, iType);
        //    return arcs.Where(o => o.ArchiveName.IndexOf(sArchiveName) > -1).FirstOrDefault();
        //}

        /// <summary>
        /// 取得指定名称的属性值

        /// </summary>
        /// <param name="arc"></param>
        /// <param name="field"></param>
        /// <returns></returns>
        //public static string PropertyVal(this KMLib.VHArchive arc, string field)
        //{
        //    string sRet = string.Empty;
        //    Type type = arc.GetType();
        //    foreach (PropertyInfo property in type.GetProperties())
        //    {
        //        if (property.Name.IsSame(field, false))
        //        {
        //            object o = property.GetValue(arc, null);
        //            sRet = o == null ? string.Empty : o.ToString();
        //            break;
        //        }
        //    }
        //    return sRet;
        //}

        /// <summary>
        /// 得到当前对象的父对象
        /// </summary>
        /// <param name="arc"></param>
        /// <returns></returns>
        //public static KMLib.VHArchive Parent(this KMLib.VHArchive arc, int iClassId)
        //{
        //    return VHHandler.GetArchiveDetail(iClassId, (int)arc.ParentID);
        //}
    }

    public static class ListXml
    {
        /// <summary>
        /// 在一个Xml List中找到名称为field，值为value的结点

        /// </summary>
        /// <param name="list"></param>
        /// <param name="field"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static XmlNode FieldOf(this List<XmlNode> list, string field, string value)
        {
            foreach (XmlNode nd in list)
            {
                foreach (XmlAttribute att in nd.Attributes)
                {
                    if (att.Name == field && att.Value == value)
                    {
                        return nd;
                    }
                }
            }
            return null;
        }
    }
    //public class Encrypt
    //{
    //    private static Client client = new Client();	// 加密解工具类
    //    private static string m_userId = "sdk";			// 接口使用用户
    //    private static string m_password = "sdk";		// 接口使用用户的密码
    //    public static string UserID
    //    {
    //        get { return m_userId; }
    //        set { m_userId = value; }
    //    }

    //    public static string PassWord
    //    {
    //        get { return m_password; }
    //        set { m_password = value; }
    //    }

    //    private static string m_strfilePath = "";// 待加密的文件
    //    private static string m_strName = "前沿加密测试";
    //    public static string filePath
    //    {
    //        get { return m_strfilePath; }
    //        set { m_strfilePath = value; }
    //    }

    //    public static string NameAll
    //    {
    //        get { return m_strName; }
    //        set { m_strName = value; }
    //    }

    //    public static void EncryptInitial(string strServerIP, string strServerPort)
    //    {
    //        if (strServerIP != null && strServerIP.Length > 0 && strServerPort != null && strServerPort.Length > 0)
    //        {
    //            client.setDrmPolicyServer(strServerIP, int.Parse(strServerPort)); // 文档加密服务器的地址
    //            if (!client.isEnable()) // 加密工具是否有效
    //            {
    //                try
    //                {
    //                    bool bl = client.SDKInit(UserID, PassWord);// 完成初始化之后，可以执行加密和解密
    //                }
    //                catch (Exception ex)
    //                {

    //                }
    //            }
    //        }
    //    }

        /// <summary>
        /// 加密主函数
        /// </summary>
    //    public static void EncryptFiles(string strLoginID)
    //    {
    //        try
    //        {
    //            //client.encryptDownload(filePath, strLoginID, cn.net.drm.edi.util.Permission.READ | cn.net.drm.edi.util.Permission.EDIT);
    //            client.encrypt(filePath, strLoginID, cn.net.drm.edi.util.SecretLevel.公开, Guid.NewGuid());
    //        }
    //        catch (System.Exception ex)
    //        {

    //        }
    //    }

    //    /// <summary>
    //    /// 解密函数
    //    /// </summary>
    //    public static void DisEncryptFiles()
    //    {
    //        try
    //        {
    //            client.decrypt(filePath);
    //        }
    //        catch (System.Exception ex)
    //        {

    //        }
    //    }
    //}
}
